<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style rel="stylesheet">
        .loading {
            cursor: pointer;
            font-size: 0.5em;
            color: white;
            font-weight: 100;
            width: 5.4em;
            height: 5.4em;
            line-height: 5.4em;
            text-align: center;
            position: fixed;
            left: 50%;
            top: 50%;
            margin-left: -1.5em;
            margin-top: -1.5em;
            border-radius: 100%;
            border: 2px solid #00d8ff;
            box-shadow: 0 0 0 0 #17262b, 0 0 2px 3px #00d8ff, 0 0 4px 25px #17262b, 0 0 1px 32px #17262b, 0 0 32px 25px #00d8ff, 0 0 32px 25px #17262b;
            animation: pulse 1.4s linear infinite;
            transition: all 0.3s ease;
        }

        .loading:before {
            box-sizing: border-box;
            content: "";
            border-radius: 100%;
            animation: rotate 0.45s linear infinite;
            transition: opacity 1s ease 0.6s, border 0.4s ease 0s, width 0.4s ease 0.2s, height 0.4s ease 0.2s, margin 0.4s ease 0.2s;
            position: absolute;
            left: 50%;
            top: 50%;
            width: 4.65em;
            height: 4.65em;
            margin-left: -2.325em;
            margin-top: -2.325em;
            border-top: 1px solid #3bff00;
            border-bottom: 1px solid #ff3f00;
        }

        .loading.danger {
            border-color: #ff3f00;
            box-shadow: 0 0 10px 2px #ff3f00;
            animation: none;
        }

        .loading.danger:before {
            border-color: #ff3f00;
            opacity: 0;
            width: 21em;
            height: 21em;
            margin-left: -10.5em;
            margin-top: -10.5em;
        }

        .loading.ok {
            border-color: #3bff00;
            box-shadow: 0 0 10px 0px #3bff00;
            animation: none;
        }

        .loading.ok:before {
            border-color: #3bff00;
            opacity: 0;
            width: 4.8em;
            height: 4.8em;
            margin-left: -2.4em;
            margin-top: -2.4em;
        }

        @keyframes rotate {
            0% {
                transform: rotate(0deg);
            }
            100% {
                transform: rotate(360deg);
            }
        }

        @keyframes pulse {
            0% {
                box-shadow: 0 0 0 0 #17262b, 0 0 2px 3px #00d8ff, 0 0 1px 32px #17262b, 0 0 32px 25px #00d8ff;
            }
            49.9% {
                box-shadow: 0 0 1px 32px #17262b, 0 0 32px 25px #00d8ff, 0 0 1px 64px #17262b, 0 0 60px 25px #00d8ff;
            }
            50% {
                box-shadow: 0 0 0 0 #17262b, 0 0 2px 3px #00d8ff, 0 0 1px 32px #17262b, 0 0 32px 25px #00d8ff;
            }
            100% {
                box-shadow: 0 0 1px 32px #17262b, 0 0 32px 25px #00d8ff, 0 0 1px 64px #17262b, 0 0 60px 25px #00d8ff;
            }
        }

        body,
        html {
            background: #17262b;
            color: white;
            font-family: "Lato";
            font-weight: 900;
            text-align: center;
            padding: 1em;
        }

        p {
            font-size: 1.2em;
            position: relative;
            z-index: 88;
            opacity: 0.6;
        }

        p small {
            font-weight: 100;
        }
    </style>
    <script src="../jquery.js"></script>
    <script>
        var t, togg = true;

        $(".loading").on({

            "click": function (e) {

                clearTimeout(t);

                togg = !togg;
                $(this)
                        .trigger("reset");

            },

            "saved": function (e) {

                $(this)
                        .addClass("ok")
                        .removeClass("danger")
                        .text("OK");

            },

            "error": function (e) {

                $(this)
                        .addClass("danger")
                        .removeClass("ok")
                        .text("ERROR");

            },

            "reset": function (e) {

                $(this)
                        .removeClass("ok danger")
                        .text("SAVING");

                t = setTimeout(function () {

                    if (!togg) {

                        $(".loading")
                                .trigger("saved");

                    } else {

                        $(".loading")
                                .trigger("error");

                    }

                }, 3000);

            }

        }).trigger("reset");
    </script>
</head>
<body>
<b class="loading">Saving</b>

<p>Click on the little doofy and it'll reset
    <br>
    <small> and trigger the opposite event (3s delay)</small>
</p>
</body>
</html>
